#ifndef _BOARD_CONFIG_H_
#define _BOARD_CONFIG_H_

#include <driver/gpio.h>

#define AUDIO_INPUT_SAMPLE_RATE 24000
#define AUDIO_OUTPUT_SAMPLE_RATE 24000

// 副屏选择，如果有副屏，则需打开SUB_DISPLAY_EN和对应屏幕
#define SUB_DISPLAY_EN 1
#define FORD_VFD_EN 0
#define HNA_16MM65T_EN 0
#define BOE_48_1504FN_EN 0
#define FTB_13_BT_247GN_EN 0
#define HUV_13SS16T_EN 01

// 板子选择
#define ESP_D103 0
#define ESP_DUAL_DISPLAY 0
#define ESP_DUAL_DISPLAY_V2 01

#if ESP_D103
#ifdef AUDIO_I2S_METHOD_SIMPLEX

#define AUDIO_I2S_MIC_GPIO_WS GPIO_NUM_4
#define AUDIO_I2S_MIC_GPIO_SCK GPIO_NUM_5
#define AUDIO_I2S_MIC_GPIO_DIN GPIO_NUM_6
#define AUDIO_I2S_SPK_GPIO_DOUT GPIO_NUM_7
#define AUDIO_I2S_SPK_GPIO_BCLK GPIO_NUM_15
#define AUDIO_I2S_SPK_GPIO_LRCK GPIO_NUM_16

#else

#define NTP_SERVER1 "pool.ntp.org"
#define NTP_SERVER2 "time.nist.gov"
#define DEFAULT_TIMEZONE "CST-8"

#define AUDIO_I2S_GPIO_WS GPIO_NUM_42
#define AUDIO_I2S_GPIO_BCLK GPIO_NUM_41
#define AUDIO_I2S_GPIO_DIN GPIO_NUM_40
#define AUDIO_I2S_GPIO_DOUT GPIO_NUM_39

#endif

#define USE_TOUCH 1
#if USE_TOUCH
#define TOUCH_MASTER_NUM I2C_NUM_1
#define TOUCH_SDA_NUM GPIO_NUM_47
#define TOUCH_SCL_NUM GPIO_NUM_48
#define TOUCH_RST_NUM GPIO_NUM_3
#define TOUCH_INT_NUM GPIO_NUM_45
#endif
#define ADC_UNIT ADC_UNIT_1
#define BAT_ADC_CHANNEL ADC_CHANNEL_4  // GPIO_NUM_2
#define DIMM_ADC_CHANNEL ADC_CHANNEL_3 // GPIO_NUM_1
#define DEFAULT_VREF 1100              // 参考电压，单位为 mV，可根据实际情况调整

#define IIC_MASTER_NUM I2C_NUM_0
#define IIC_SDA_NUM GPIO_NUM_7
#define IIC_SCL_NUM GPIO_NUM_6
#define I2C_MASTER_TX_BUF_DISABLE 0 /*!< I2C master do not need buffer */
#define I2C_MASTER_RX_BUF_DISABLE 0 /*!< I2C master do not need buffer */

#define BUILTIN_LED_GPIO GPIO_NUM_1

#define TOUCH_BUTTON_GPIO GPIO_NUM_0

#define LCD_HOST SPI2_HOST
#define VFD_HOST SPI3_HOST

#define DISPLAY_WIDTH 536
#define DISPLAY_HEIGHT 240
#define DISPLAY_MIRROR_X true
#define DISPLAY_MIRROR_Y false
#define DISPLAY_SWAP_XY true

#define DISPLAY_OFFSET_X 0
#define DISPLAY_OFFSET_Y 0

#define PIN_NUM_LCD_CS (GPIO_NUM_9)
#define PIN_NUM_LCD_PCLK (GPIO_NUM_10)
#define PIN_NUM_LCD_DATA0 (GPIO_NUM_11)
#define PIN_NUM_LCD_DATA1 (GPIO_NUM_12)
#define PIN_NUM_LCD_DATA2 (GPIO_NUM_13)
#define PIN_NUM_LCD_DATA3 (GPIO_NUM_14)
#define PIN_NUM_LCD_RST (GPIO_NUM_21)
#define PIN_NUM_BK_LIGHT (GPIO_NUM_NC)
#define PIN_NUM_LCD_POWER (GPIO_NUM_46)

// #define PIN_NUM_SD_CMD (GPIO_NUM_43)
// #define PIN_NUM_SD_CLK (GPIO_NUM_42)
// #define PIN_NUM_SD_D0 (GPIO_NUM_41)
// #define PIN_NUM_SD_D1 (GPIO_NUM_40)
// #define PIN_NUM_SD_D2 (GPIO_NUM_45)
// #define PIN_NUM_SD_D3 (GPIO_NUM_44)
// #define PIN_NUM_SD_CDZ (GPIO_NUM_39)

#define PIN_NUM_VFD_DATA0 (GPIO_NUM_15)
#define PIN_NUM_VFD_PCLK (GPIO_NUM_16)
#define PIN_NUM_VFD_CS (GPIO_NUM_17)
#define PIN_NUM_VFD_EN (GPIO_NUM_8)

#define PIN_NUM_POWER_EN (GPIO_NUM_NC)
#elif ESP_DUAL_DISPLAY
#ifdef AUDIO_I2S_METHOD_SIMPLEX

#define AUDIO_I2S_MIC_GPIO_WS GPIO_NUM_4
#define AUDIO_I2S_MIC_GPIO_SCK GPIO_NUM_5
#define AUDIO_I2S_MIC_GPIO_DIN GPIO_NUM_6
#define AUDIO_I2S_SPK_GPIO_DOUT GPIO_NUM_7
#define AUDIO_I2S_SPK_GPIO_BCLK GPIO_NUM_15
#define AUDIO_I2S_SPK_GPIO_LRCK GPIO_NUM_16

#else

#define NTP_SERVER1 "pool.ntp.org"
#define NTP_SERVER2 "time.nist.gov"
#define DEFAULT_TIMEZONE "CST-8"

#define AUDIO_I2S_GPIO_WS GPIO_NUM_21   // 以适配
#define AUDIO_I2S_GPIO_BCLK GPIO_NUM_14 // 以适配
#define AUDIO_I2S_GPIO_DIN GPIO_NUM_47  // 以适配
#define AUDIO_I2S_GPIO_DOUT GPIO_NUM_13 // 以适配

#endif

#define USE_TOUCH 1
#if USE_TOUCH
#define TOUCH_MASTER_NUM I2C_NUM_1
#define TOUCH_SDA_NUM GPIO_NUM_3
#define TOUCH_SCL_NUM GPIO_NUM_8
#define TOUCH_INT_NUM GPIO_NUM_9
#define TOUCH_MIRROR_X false
#define TOUCH_MIRROR_Y true
#define TOUCH_SWAP_XY true
#endif
#define ADC_UNIT ADC_UNIT_1
#define BAT_ADC_CHANNEL ADC_CHANNEL_1  // GPIO_NUM_2
#define DIMM_ADC_CHANNEL ADC_CHANNEL_0 // GPIO_NUM_1
#define DEFAULT_VREF 1100              // 参考电压，单位为 mV，可根据实际情况调整

#define IIC_MASTER_NUM I2C_NUM_0
#define IIC_SDA_NUM GPIO_NUM_45
#define IIC_SCL_NUM GPIO_NUM_48
#define I2C_MASTER_TX_BUF_DISABLE 0 /*!< I2C master do not need buffer */
#define I2C_MASTER_RX_BUF_DISABLE 0 /*!< I2C master do not need buffer */

// #define BUILTIN_LED_GPIO GPIO_NUM_1 // 以适配
// #define BOOT_BUTTON_GPIO GPIO_NUM_0 // 以适配
// #define RESET_NVS_BUTTON_GPIO     GPIO_NUM_1
// #define RESET_FACTORY_BUTTON_GPIO GPIO_NUM_4

#define TOUCH_BUTTON_GPIO GPIO_NUM_0
// #define VOLUME_ENCODER1_GPIO GPIO_NUM_14 // 以适配-encoder
// #define VOLUME_ENCODER2_GPIO GPIO_NUM_16 // 以适配-encoder

#define LCD_HOST SPI2_HOST
#define VFD_HOST SPI3_HOST
#define SD_HOST SPI3_HOST

#define DISPLAY_WIDTH 536
#define DISPLAY_HEIGHT 240
#define DISPLAY_MIRROR_X false
#define DISPLAY_MIRROR_Y false
#define DISPLAY_SWAP_XY true

#define DISPLAY_OFFSET_X 0
#define DISPLAY_OFFSET_Y 0

#define PIN_NUM_LCD_CS (GPIO_NUM_5)
#define PIN_NUM_LCD_PCLK (GPIO_NUM_6)
#define PIN_NUM_LCD_DATA0 (GPIO_NUM_7)
#define PIN_NUM_LCD_DATA1 (GPIO_NUM_15)
#define PIN_NUM_LCD_DATA2 (GPIO_NUM_16)
#define PIN_NUM_LCD_DATA3 (GPIO_NUM_17)
#define PIN_NUM_LCD_RST (GPIO_NUM_18)
#define PIN_NUM_LCD_TE (GPIO_NUM_9)
#define PIN_NUM_BK_LIGHT (GPIO_NUM_NC)
#define PIN_NUM_LCD_POWER (GPIO_NUM_NC)

#define PIN_NUM_POWER_EN (GPIO_NUM_4)

#define PIN_NUM_VFD_DATA0 (GPIO_NUM_10)
#define PIN_NUM_VFD_PCLK (GPIO_NUM_11)
#define PIN_NUM_VFD_CS (GPIO_NUM_12)
#define PIN_NUM_VFD_EN (GPIO_NUM_NC)
#define PIN_NUM_VFD_RE (GPIO_NUM_NC)

#define PIN_NUM_SD_CS (GPIO_NUM_39)
#define PIN_NUM_SD_MOSI (GPIO_NUM_40)
#define PIN_NUM_SD_CLK (GPIO_NUM_41)
#define PIN_NUM_SD_MISO (GPIO_NUM_42)

#define PIN_NUM_SD_CMD (GPIO_NUM_40)
#define PIN_NUM_SD_CLK (GPIO_NUM_41)
#define PIN_NUM_SD_D0 (GPIO_NUM_42)
#define PIN_NUM_SD_D1 (GPIO_NUM_44)
#define PIN_NUM_SD_D2 (GPIO_NUM_43)
#define PIN_NUM_SD_D3 (GPIO_NUM_39)
#define PIN_NUM_SD_CDZ (GPIO_NUM_NC)
#elif ESP_DUAL_DISPLAY_V2
#ifdef AUDIO_I2S_METHOD_SIMPLEX

#define AUDIO_I2S_MIC_GPIO_WS GPIO_NUM_4
#define AUDIO_I2S_MIC_GPIO_SCK GPIO_NUM_5
#define AUDIO_I2S_MIC_GPIO_DIN GPIO_NUM_6
#define AUDIO_I2S_SPK_GPIO_DOUT GPIO_NUM_7
#define AUDIO_I2S_SPK_GPIO_BCLK GPIO_NUM_15
#define AUDIO_I2S_SPK_GPIO_LRCK GPIO_NUM_16

#else

#define NTP_SERVER1 "pool.ntp.org"
#define NTP_SERVER2 "time.nist.gov"
#define DEFAULT_TIMEZONE "CST-8"

#define AUDIO_I2S_GPIO_WS GPIO_NUM_21   // 以适配
#define AUDIO_I2S_GPIO_BCLK GPIO_NUM_14 // 以适配
#define AUDIO_I2S_GPIO_DIN GPIO_NUM_47  // 以适配
#define AUDIO_I2S_GPIO_DOUT GPIO_NUM_13 // 以适配

#endif

#define USE_TOUCH 1
#if USE_TOUCH
#define TOUCH_MASTER_NUM I2C_NUM_1
#define TOUCH_SDA_NUM GPIO_NUM_18
#define TOUCH_SCL_NUM GPIO_NUM_17
#define TOUCH_INT_NUM GPIO_NUM_8
#define TOUCH_MIRROR_X false
#define TOUCH_MIRROR_Y true
#define TOUCH_SWAP_XY true
#endif
#define ADC_UNIT ADC_UNIT_1
// #define BAT_ADC_CHANNEL ADC_CHANNEL_1  // GPIO_NUM_2
#define DIMM_ADC_CHANNEL ADC_CHANNEL_0 // GPIO_NUM_1
#define DEFAULT_VREF 1100              // 参考电压，单位为 mV，可根据实际情况调整

#define WAKE_INT_NUM GPIO_NUM_3

#define IIC_MASTER_NUM I2C_NUM_0
#define IIC_SDA_NUM GPIO_NUM_45
#define IIC_SCL_NUM GPIO_NUM_48
#define I2C_MASTER_TX_BUF_DISABLE 0 /*!< I2C master do not need buffer */
#define I2C_MASTER_RX_BUF_DISABLE 0 /*!< I2C master do not need buffer */

#define BUILTIN_LED_GPIO GPIO_NUM_1 
// #define BOOT_BUTTON_GPIO GPIO_NUM_0 // 以适配
// #define RESET_NVS_BUTTON_GPIO     GPIO_NUM_1
// #define RESET_FACTORY_BUTTON_GPIO GPIO_NUM_4

#define TOUCH_BUTTON_GPIO GPIO_NUM_0
// #define VOLUME_ENCODER1_GPIO GPIO_NUM_14 // 以适配-encoder
// #define VOLUME_ENCODER2_GPIO GPIO_NUM_16 // 以适配-encoder

#define LCD_HOST SPI2_HOST
#define VFD_HOST SPI3_HOST

#define DISPLAY_WIDTH 536
#define DISPLAY_HEIGHT 240
#define DISPLAY_MIRROR_X false
#define DISPLAY_MIRROR_Y false
#define DISPLAY_SWAP_XY true

#define DISPLAY_OFFSET_X 0
#define DISPLAY_OFFSET_Y 0

enum ExternalIO
{
    TPS_PS = 0,
    VCC_DECT,
    SD_EN = 3,
    MIC_EN,
    OLED_RST,
    OLED_EN,
    VFD_EN,
};

const char *DectectCHEnum[] = {"VFD", "VCC", "BAT"};
enum DectectCH
{
    VFD_PW = 0,
    VCC_PW,
    BAT_PW,
};

#define PIN_NUM_VCC_DECT (GPIO_NUM_9)

#define PIN_NUM_LCD_CS (GPIO_NUM_4)
#define PIN_NUM_LCD_PCLK (GPIO_NUM_5)
#define PIN_NUM_LCD_DATA0 (GPIO_NUM_6)
#define PIN_NUM_LCD_DATA1 (GPIO_NUM_7)
#define PIN_NUM_LCD_DATA2 (GPIO_NUM_15)
#define PIN_NUM_LCD_DATA3 (GPIO_NUM_16)
#define PIN_NUM_LCD_RST (GPIO_NUM_NC) // follow the pcf8574
#define PIN_NUM_LCD_TE (GPIO_NUM_NC)
#define PIN_NUM_BK_LIGHT (GPIO_NUM_NC)
#define PIN_NUM_LCD_POWER (GPIO_NUM_NC) // follow the pcf8574

#define PIN_NUM_POWER_EN (GPIO_NUM_NC) // follow the pcf8574

#define PIN_NUM_VFD_DATA0 (GPIO_NUM_10)
#define PIN_NUM_VFD_PCLK (GPIO_NUM_11)
#define PIN_NUM_VFD_CS (GPIO_NUM_12)
#define PIN_NUM_VFD_RE (GPIO_NUM_46)
#define PIN_NUM_VFD_EN (GPIO_NUM_NC) // follow the pcf8574

#define PIN_NUM_SD_CMD (GPIO_NUM_40)
#define PIN_NUM_SD_CLK (GPIO_NUM_41)
#define PIN_NUM_SD_D0 (GPIO_NUM_42)
#define PIN_NUM_SD_D1 (GPIO_NUM_2)
#define PIN_NUM_SD_D2 (GPIO_NUM_38)
#define PIN_NUM_SD_D3 (GPIO_NUM_39)
// #define PIN_NUM_SD_CDZ (GPIO_NUM_43)
#define PIN_NUM_SD_CDZ (GPIO_NUM_NC)
#define PIN_NUM_SD_EN (GPIO_NUM_NC) // follow the pcf8574
#elif ESP_DUAL_DISPLAY
#ifdef AUDIO_I2S_METHOD_SIMPLEX

#define AUDIO_I2S_MIC_GPIO_WS GPIO_NUM_4
#define AUDIO_I2S_MIC_GPIO_SCK GPIO_NUM_5
#define AUDIO_I2S_MIC_GPIO_DIN GPIO_NUM_6
#define AUDIO_I2S_SPK_GPIO_DOUT GPIO_NUM_7
#define AUDIO_I2S_SPK_GPIO_BCLK GPIO_NUM_15
#define AUDIO_I2S_SPK_GPIO_LRCK GPIO_NUM_16

#else

#define NTP_SERVER1 "pool.ntp.org"
#define NTP_SERVER2 "time.nist.gov"
#define DEFAULT_TIMEZONE "CST-8"

#define AUDIO_I2S_GPIO_WS GPIO_NUM_10   // 以适配
#define AUDIO_I2S_GPIO_BCLK GPIO_NUM_11 // 以适配
#define AUDIO_I2S_GPIO_DIN GPIO_NUM_13  // 以适配
#define AUDIO_I2S_GPIO_DOUT GPIO_NUM_12 // 以适配

#endif

#define USE_TOUCH 1
#if USE_TOUCH
#define TOUCH_MASTER_NUM I2C_NUM_1
#define TOUCH_SDA_NUM GPIO_NUM_41
#define TOUCH_SCL_NUM GPIO_NUM_40
#endif
#define ADC_UNIT ADC_UNIT_1
#define ADC_CHANNEL ADC_CHANNEL_3 // GPIO_NUM_4
#define DEFAULT_VREF 1100         // 参考电压，单位为 mV，可根据实际情况调整

#define IIC_MASTER_NUM I2C_NUM_0
#define IIC_SDA_NUM GPIO_NUM_3
#define IIC_SCL_NUM GPIO_NUM_2
#define I2C_MASTER_TX_BUF_DISABLE 0 /*!< I2C master do not need buffer */
#define I2C_MASTER_RX_BUF_DISABLE 0 /*!< I2C master do not need buffer */

#define BUILTIN_LED_GPIO GPIO_NUM_1 // 以适配
#define BOOT_BUTTON_GPIO GPIO_NUM_0 // 以适配
// #define RESET_NVS_BUTTON_GPIO     GPIO_NUM_1
// #define RESET_FACTORY_BUTTON_GPIO GPIO_NUM_4

#define TOUCH_BUTTON_GPIO GPIO_NUM_15    // 以适配-encoder
#define VOLUME_ENCODER1_GPIO GPIO_NUM_14 // 以适配-encoder
#define VOLUME_ENCODER2_GPIO GPIO_NUM_16 // 以适配-encoder

#define LCD_HOST SPI2_HOST
#define VFD_HOST SPI3_HOST

#define DISPLAY_WIDTH 536
#define DISPLAY_HEIGHT 240
#define DISPLAY_MIRROR_X true
#define DISPLAY_MIRROR_Y false
#define DISPLAY_SWAP_XY true

#define DISPLAY_OFFSET_X 0
#define DISPLAY_OFFSET_Y 0

#define PIN_NUM_LCD_CS (GPIO_NUM_6)
#define PIN_NUM_LCD_PCLK (GPIO_NUM_47)
#define PIN_NUM_LCD_DATA0 (GPIO_NUM_18)
#define PIN_NUM_LCD_DATA1 (GPIO_NUM_7)
#define PIN_NUM_LCD_DATA2 (GPIO_NUM_48)
#define PIN_NUM_LCD_DATA3 (GPIO_NUM_5)
#define PIN_NUM_LCD_RST (GPIO_NUM_17)
#define PIN_NUM_BK_LIGHT (GPIO_NUM_NC)
#define PIN_NUM_LCD_POWER (GPIO_NUM_38)

// #define PIN_NUM_SD_CMD (GPIO_NUM_43)
// #define PIN_NUM_SD_CLK (GPIO_NUM_42)
// #define PIN_NUM_SD_D0 (GPIO_NUM_41)
// #define PIN_NUM_SD_D1 (GPIO_NUM_40)
// #define PIN_NUM_SD_D2 (GPIO_NUM_45)
// #define PIN_NUM_SD_D3 (GPIO_NUM_44)
// #define PIN_NUM_SD_CDZ (GPIO_NUM_39)

#define PIN_NUM_VFD_DATA0 (GPIO_NUM_42)
#define PIN_NUM_VFD_PCLK (GPIO_NUM_45)
#define PIN_NUM_VFD_CS (GPIO_NUM_46)
#endif

#endif // _BOARD_CONFIG_H_
